# PowerShell 版本的启动脚本（Windows 10/11 推荐）

$ErrorActionPreference = "Stop"

# 进入项目目录
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $scriptPath

Write-Host "🚀 启动疫苗预约系统..." -ForegroundColor Green

# 检查 Docker 是否运行
try {
    docker info | Out-Null
} catch {
    Write-Host "❌ 错误: Docker 未运行，请先启动 Docker Desktop" -ForegroundColor Red
    Read-Host "按 Enter 键退出"
    exit 1
}

# 启动 Docker Compose 服务
Write-Host "📦 启动 MySQL 和 Redis 容器..." -ForegroundColor Cyan
docker compose up -d

# 等待 MySQL 启动
Write-Host "⏳ 等待 MySQL 启动..." -ForegroundColor Yellow
Start-Sleep -Seconds 10

# 检查容器状态
Write-Host "📊 当前容器状态：" -ForegroundColor Cyan
docker compose ps

Write-Host ""
Write-Host "✅ 数据库服务已就绪！" -ForegroundColor Green
Write-Host "   - MySQL: localhost:3306  (root / 123456)"
Write-Host "   - Redis: localhost:6379  (密码 123456)"
Write-Host ""
Write-Host "🚀 接下来将启动 Spring Boot（按 Ctrl+C 可停止）。" -ForegroundColor Yellow
Write-Host "   若要关闭 MySQL/Redis，请另开终端执行 stop.ps1 或 stop.bat"
Write-Host ""

# 检查 JAVA_HOME
if (-not $env:JAVA_HOME) {
    Write-Host "⚠️  警告: 未设置 JAVA_HOME 环境变量" -ForegroundColor Yellow
    Write-Host "   请先设置 JAVA_HOME 指向 JDK 11 的安装目录"
    Write-Host "   例如: `$env:JAVA_HOME = 'C:\Program Files\Java\jdk-11'"
    Write-Host ""
    Write-Host "   或者使用 Git Bash 运行 start.sh"
    Read-Host "按 Enter 键退出"
    exit 1
}

# 设置 PATH
$env:PATH = "$env:JAVA_HOME\bin;$env:PATH"

# 前台启动 Spring Boot
mvn spring-boot:run

